﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2023 Glodon.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

// Owner: zhuxf  
// Co-Owner: 

#pragma once
#include "GRepModule.h"
#include "IElementViewSpecificShapeComponent.h"
#include "DbDataSchema.h"
#include "NdbObjectSchematic.h"
#include "IExternalObject.h"
#include "ElementCreationOptions.h"
#include "IElementParentReporter.h"
#include "ElementId.h"
#include "Matrix4d.h"

namespace gcmp
{
    class IElement;
    class NdbObject;
    class IDocument;
    class IGraphicsNodeReference;
}

namespace Sample
{
    // 
    class SampleViewSpecificElement : public gcmp::NdbObjectSchematic, public gcmp::IExternalObject
    {
    private:
        DBOBJECT_DATA_BEGIN(Sample, SampleViewSpecificElement, gcmp::NdbObjectSchematic, 5BB51E2C - 1E52 - 49FC - A715 - F38BA20340FF, GRepModule)
            DATA_TRANSIENT(gcmp::IElement*, pOwnerElement)
            DBOBJECT_DATA_END
    public:
        static SampleViewSpecificElement* Create(gcmp::IDocument* pDoc, gcmp::ElementCreationOptions eco = gcmp::ElementCreationOptions::Normal);

        virtual gcmp::NdbObject* GetTopOwnerObject() const override;
        virtual bool FinishEditing() override { return true; };
        virtual gcmp::IElement* GetOwnerElement() override { return m_pOwnerElement; };
        virtual const gcmp::IElement* GetOwnerElement() const override { return m_pOwnerElement; };
        virtual void ReportParents(gcmp::IElementParentReporter& elementParentReporter) const override;
        virtual bool SetOwnerElement(gcmp::IElement* pOwnerElement) override { m_pOwnerElement = pOwnerElement; return true; };
        virtual void UpdateForWeakParentDeletion(const std::set<gcmp::ElementId>& deletedElementIds) override;
        bool Transform(const gcmp::Matrix4d& matrix);
    };

    class ViewSpecificShapeCustomComponent : public gcmp::NdbObjectSchematic,
        public gcmp::IElementViewSpecificShapeComponent
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(Sample, ViewSpecificShapeCustomComponent, gcmp::NdbObjectSchematic,
			CFC634C1 - FAE9 - 4829 - 9C96 - 40BD99123ABA, GRepModule, gcmp::IElementViewSpecificShapeComponent)
            DATA(gcmp::OwnerPtr<gcmp::IRenderPriorityOffsetProvider>, RenderPriorityOffsetProvider)
            DATA_TRANSIENT(gcmp::IElement*, pOwnerElement)
            DATA(gcmp::OwnerPtr<gcmp::IGraphicsNodeVisibilityCustomizer>, GraphicsNodeVisibilityCustomizer)
        DBOBJECT_DATA_END
    public:
        virtual ~ViewSpecificShapeCustomComponent();

    public:
        virtual bool SetOwnerElement(gcmp::IElement* pOwnerElement) override;
        virtual gcmp::IElement* GetOwnerElement() override { return m_pOwnerElement; }
        virtual const gcmp::IElement* GetOwnerElement() const override { return m_pOwnerElement; }

    public: //实现NdbObject接口
        virtual gcmp::NdbObject* GetTopOwnerObject() const override;

    public:
        virtual bool IsVisibleInModelView(const gcmp::IModelView* pModelView) const override;
        virtual gcmp::OwnerPtr<gcmp::IGraphicsElementShape> CreateViewSpecificElementShape(const gcmp::IModelView* pModelView) const override;
        virtual bool IsCuttableByModelViewRange(const gcmp::IModelView* pModelView) const override { return false; }
        virtual void ReportDependentElements(std::vector<gcmp::ElementId>& dependentElementIds) const override {};

        virtual void SetRenderPriorityOffsetProvider(gcmp::OwnerPtr<gcmp::IRenderPriorityOffsetProvider> opProvider) override;
        virtual const gcmp::IRenderPriorityOffsetProvider* GetRenderPriorityOffsetProvider() const override;
        virtual gcmp::IRenderPriorityOffsetProvider* GetRenderPriorityOffsetProvider() override;

        virtual void SetGraphicsNodeVisibilityCustomizer(gcmp::OwnerPtr<gcmp::IGraphicsNodeVisibilityCustomizer> opCustomizer) override;
        virtual const gcmp::IGraphicsNodeVisibilityCustomizer* GetGraphicsNodeVisibilityCustomizer() const override;
        virtual gcmp::IGraphicsNodeVisibilityCustomizer* GetGraphicsNodeVisibilityCustomizer() override;
    };
}
